package com.tansun.rule.config;

import java.io.IOException;
import java.util.Properties;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.stereotype.Component;

@Component
public class CommonConfig {
	  private static Properties props ;

	    public CommonConfig(){

	        try {
	            Resource resource = new ClassPathResource("/easycare.properties");//
	            props = PropertiesLoaderUtils.loadProperties(resource);
	            AppConfiguration.isNeedLog = CommonConfig.getProperty("redis.isenable");
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	    }


	    /**
	     * 获取属性
	     * @param key
	     * @return
	     */
	    public static String getProperty(String key){

	        return props == null ? null :  props.getProperty(key);

	    }

	    /**
	     * 获取属性
	     * @param key 属性key
	     * @param defaultValue 属性value
	     * @return
	     */
	    public static String getProperty(String key,String defaultValue){

	         return props == null ? null : props.getProperty(key, defaultValue);

	    }

	    /**
	     * 获取properyies属性
	     * @return
	     */
	    public static Properties getProperties(){
	        return props;
	    }
}
